tongfusoft.user = function() {
}
var currUserId = "";
tongfusoft.user.prototype = {
		//获取用户信息显示在列表上
		userList : function() {

			var table = new tongfusoft.table();
			var columns = [
					{
						"data" : "userId"
					},
					{
						"data" : "loginName"
					},
					{
						"data" : "displayName"
					},
					{
						"data" : "mobile"
					},
					{
						"data" : "email"
					},
					{
						"data" : "lastName"
					},
					{
						"data" : "lastUpdDate"
					},
					{
						"data" : "userId",
						"render" : function(data, type, full, meta) {
							var detailbut = '<button userId="'
								+ data
								+ '" onclick="new tongfusoft.user().userDetail(this)" type="button" class="detBtn btn btn-default btn-sm "><em class="icon-list"></em></button>'
						    
							
						    var delbut = '';	
							if( full.displayName == 'admin'){
								delbut = '<button type="button" class="detBtn btn btn-default btn-sm disabled"><em class="fa fa-trash"></em></button>';
							}else{
								delbut = '<button userId="'
								+ data	+ '" onclick="new tongfusoft.user().userDel(this)" type="button" class="detBtn btn btn-default btn-sm "><em class="fa fa-trash"></em></button>'	
							}
							
							var editbut = '<button userId="'
									+ data
									+ '" onclick="new tongfusoft.user().userEdit(this)" type="button" class="detBtn btn btn-default btn-sm "><em class="fa fa-edit"></em></button>'

							return detailbut + editbut + delbut;
						}

					} ]

			table.dataTable('userTable', 'manager/user/query', columns, null);
		},
		
		//跳转至添加用户界面
		addBtnUser : function(){
			$("#addBtnUser").click(function() {
				window.location.href=common.getContextPath('manager/user/addPage');
			})
		},
	
		//跳转至详情页
		userDetail : function(obj){
			window.location.href=common.getContextPath('manager/user/detailPage/'+$(obj).attr("userId"));
		},
		
		//删除用户
		userDel : function(obj) {

			swal({
				title : "是否确认?",
				text : "",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "删除",
				cancelButtonText : "取消",
				closeOnConfirm : true
			}, function() {
				common.ajaxSubmitOnSuccess({
					"userId" : $(obj).attr("userId")
				}, 'manager/user/del', function(data) {

					if (data.state == 'success') {

						$('#userTable').DataTable().ajax.reload();
					} else{
						toastr["error"]('删除失败!');
					}

				}, "del")
			});

		},
		
		//跳转至用户编辑页面
		userEdit : function(obj){
			common.post('currUser', {
			}, function(data) {
				if (data.state == 'success') {
					currUserId = data.data.userId;
				}
			});
			if(currUserId == $(obj).attr("userId")){
				window.location.href=common.getContextPath("manager/user/editPage/?userId="+currUserId+"&&opr=repassword");
			}else{
				window.location.href=common.getContextPath("manager/user/editPage/?userId="+$(obj).attr("userId")+"&&opr=edit");
			}
		}
		
}

$(function(){
	
	var user = new tongfusoft.user();
	//用户显示
	user.userList();
	//跳转至用户添加页面
	user.addBtnUser();
})